<!--
	作者：Sariay
	时间：2018-09-25
	描述：There may be a bug, but don't worry, QiLing(器灵) says that it can work normally!
-->
<!DOCTYPE html>
<html class="html-loading">
		

<head><meta name="generator" content="Hexo 3.8.0">
	<meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <title>
    
      nginx、pyenv配置 | SorrisoYi
    
  </title>
  <meta name="author" content="SorrisoYi">
  <meta name="keywords" content>
  <meta name="description" content="blog">
	<!-- favicon -->
  <link rel="shortcut icon" href="https://addyzk.github.io/Random-img/favicon.ico">

  <!-- css -->
  <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="../../../../css/Annie.css">
  
  <!-- jquery -->
	<script src="../../../../js/jquery.min.js"></script>

  <!-- leancloud -->
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
<script src="../../../../js/leancloud.js"></script>
</head>
	<body>
		<!-- Preloader -->

	<div id="preloader">
		<div class="pre-container">
			
				<div class="spinner">
					<div class="double-bounce1"></div>
					<div class="double-bounce2"></div>
				</div>
						
		</div>
	</div>


<!-- header -->
<header class="fixbackground" data-img-mode data-normal-src="../../../../index.html" data-random-max data-random-src="../../../../index.html">
	<div class="mask">
		<!-- Logo and navigation -->
		<div class="h-header">
			<div id="logo">
				<a href="/">
						
						<img src="https://addyzk.github.io/Random-img/logo.png" alt="Logo">
					
				</a>
			</div>
			
			<div id="navigation-show">
				<ul>
	
		<li class="menu-home">
			<a href="../../../../index.html" class="menu-item-home">主页</a>
		</li>
	
		<li class="menu-archive">
			<a href="../../../.././archives" class="menu-item-archive">归档</a>
		</li>
	
		<li class="menu-categories">
			<a href="../../../.././categories" class="menu-item-categories">分类</a>
		</li>
	
		<li class="menu-tags">
			<a href="../../../.././tags" class="menu-item-tags">标签</a>
		</li>
	
		<li class="menu-about">
			<a href="../../../.././about" class="menu-item-about">关于</a>
		</li>
	
		<li class="menu-gallery">
			<a href="../../../.././gallery" class="menu-item-gallery">相册</a>
		</li>
	

	
		<li class="menu-search">
			<a href="javascript:;" class="popup-trigger">搜索</a>
		</li>
	
</ul>
			</div>				
		</div>

		<!-- motto -->
		<div class="h-body">	
			
				<p class="motto"></p>
			
		</div>
		
		<!-- others: such as time... -->			
		<div class="h-footer">
			<a href="javascript:;" id="read-more"><i class="fa fa-angle-double-down" aria-hidden="true"></i>
			</a>

			
				<!-- 
	This is only a demo, please go to "https://time.is" to set your city time! 
-->
<style type="text/css">
	.header-date {
		font-size: 1.6rem;
		color: #fff;
		position: absolute;
		bottom: 5px;
		right: 1rem;
		writing-mode: tb-rl;
	}	
	
	.header-date a {
		border-bottom: none;
	}

	@media only screen and (max-width: 768 ) {
		.header-date {
			font-size: 1rem;
		}			
	}
</style>
<div class="header-date">
	<a href="https://time.is/Beijing" id="time_is_link" rel="nofollow"></a>
	<span id="Beijing_z43d"></span>
</div>
<script src="//widget.time.is/zh.js"></script>
<script>
	time_is_widget.init({
		Beijing_z43d:{
			template:"DATE", 
			date_format:"year年 monthname dnum日"
		}
	});
</script>
			
		</div>
	</div>
</header>

<div id="navigation-hide">
	<!-- Progress bar -->
	<div id="progress-bar"></div>

	<!-- Progress percent -->
	<div id="progress-percentage"><h1>0.0%</h1></div>

	<div class="toc-switch"><span class="switch-button">目录</span></div>

	<!-- Page title -->
	<p>
		
			当前文章&nbsp;:&nbsp;《nginx、pyenv配置》
		
	</p>

	<!-- Nav trigger for navigation-H-->
	<a class="nav-trigger"><span></span></a>
</div>

<!-- Navigation in div(id="navigation-H") -->
<nav class="nav-container" id="cd-nav">
	<div class="nav-header">
		<h3>Navigation</h3>
		<a href="javascript:;" class="nav-close"></a>
	</div>
	<div class="nav-body">
		<ul>
	
		<li class="menu-home">
			<a href="../../../../index.html" class="menu-item-home">主页</a>
		</li>
	
		<li class="menu-archive">
			<a href="../../../.././archives" class="menu-item-archive">归档</a>
		</li>
	
		<li class="menu-categories">
			<a href="../../../.././categories" class="menu-item-categories">分类</a>
		</li>
	
		<li class="menu-tags">
			<a href="../../../.././tags" class="menu-item-tags">标签</a>
		</li>
	
		<li class="menu-about">
			<a href="../../../.././about" class="menu-item-about">关于</a>
		</li>
	
		<li class="menu-gallery">
			<a href="../../../.././gallery" class="menu-item-gallery">相册</a>
		</li>
	

	
		<li class="menu-search">
			<a href="javascript:;" class="popup-trigger">搜索</a>
		</li>
	
</ul>
	</div>
	<div class="nav-footer">
		<ul>
	
		<li>
			<a href="http://github.com/addyzk" target="_blank">
				<i class="fa fa-github"></i>
			</a>
		</li>
	
		<li>
			<a href="https://weibo.com/u/2943549915" target="_blank">
				<i class="fa fa-weibo"></i>
			</a>
		</li>
	
		<li>
			<a href="http://github.com/" target="_blank">
				<i class="fa fa-pinterest"></i>
			</a>
		</li>
	
		<li>
			<a href="http://github.com/" target="_blank">
				<i class="fa fa-instagram"></i>
			</a>
		</li>
	
		<li>
			<a href="http://github.com/" target="_blank">
				<i class="fa fa-twitter"></i>
			</a>
		</li>
	
		<li>
			<a href="../../../../atom.xml" target="_blank">
				<i class="fa fa-rss"></i>
			</a>
		</li>
			
</ul>

	</div>
</nav>
			
		<!--main-->
		<main>
			<!--
	时间：2018-11-17
	描述：
		插件名称：katelog.min.js
		插件作者：KELEN
		插件来源: https://github.com/KELEN/katelog
-->

	
		<div class="layout-toc">
			<div id="layout-toc">
				<div class="k-catelog-list" id="catelog-list" data-title="文章目录"></div>
			</div>
		</div>

		
		<script src="../../../../plugin/toc/katelog.min.js"></script>

		
	 

<div class="layout-post">
	<div id="layout-post">
	<div class="article-title">
		<i class="fa fa-paper-plane-o" aria-hidden="true"></i>
		
	<a href itemprop="url">
		nginx、pyenv配置
	</a>

	</div>

	<div class="article-meta">
		<span>
			<i class="fa fa-calendar"></i>
			


	发布于

	<a href itemprop="url">
		<time datetime="2017-05-17T12:42:20.000Z" itemprop="datePublished">
	  		2017-05-17
	  </time>
	</a>
	&nbsp;





			




	更新于

	<a href itemprop="url">
		<time datetime="2017-05-17T12:42:20.000Z" itemprop="dateUpdated">
	  		2019-05-17
	  </time>
	</a> 



		</span>
		<span>
			<i class="fa fa-tags"></i>
			
	
		<a href="../../../../tags/环境配置/" class=" ">
			环境配置
		</a>
	
		
		</span>
		
		

	
    <span class="leancloud_visitors" id="_visitors" data-url data-title="nginx、pyenv配置">
       	<i class="fa fa-eye"></i>
       	热度
        <i class="leancloud_visitors_count" id="leancloud_visitors_count">0</i>
    </span>
    



	
    <span class="leancloud_likes" id="_likes" data-url data-title="nginx、pyenv配置" rel="unlike">
        <i class="fa fa-heart"></i>
        喜欢
        <i class="leancloud_likes_count" id="leancloud_likes_count">0</i>
    </span>

	</div>

	<div class="article-content" id="article-content">
		<h2 id="一、开机启动"><a href="#一、开机启动" class="headerlink" title="一、开机启动"></a>一、开机启动</h2><p>可以设置开机启动有两个地方：第一，在/etc/init.d目录下，可以将服务放到这个目录下。第二是在/etc/init.d下的rc.local，可以将需要开机启动的程序写入这个文件。可以使用sysv-rc-conf命令进行设置和查看开机启动服务。</p>
<ul>
<li><p>在/etc/init.d/下新建一个脚本test，格式如下：</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/bin/bash</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#要执行的命令</span></span><br><span class="line"><span class="keyword">exit</span> <span class="number">0</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>增加脚本可执行权限</p>
</li>
</ul>
  <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chmod +x <span class="built_in">test</span></span><br></pre></td></tr></table></figure>
<ul>
<li><p>设置开机启动</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo <span class="keyword">update</span>-rc.d <span class="keyword">test</span> <span class="keyword">defaults</span> </span><br><span class="line"><span class="comment">#90是优先级，越大优先级越低，越晚执行</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>使用sysv-rc-conf命令设置运行级别</p>
<figure class="highlight vala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#sysv-rc-conf默认没有安装，首先安装</span></span><br><span class="line">sudo apt-<span class="keyword">get</span> install sysv-rc-conf</span><br><span class="line"></span><br><span class="line"><span class="meta">#执行命令sysv-rc-conf，用空格键选中或取消指定的运行级别。</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#取消开机启动可以使用</span></span><br><span class="line">sudo update-rc.d -f 脚本名  remove</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="二、防火墙"><a href="#二、防火墙" class="headerlink" title="二、防火墙"></a>二、防火墙</h2><p>UFW或Uncomplicated Firewall是iptables的接口，旨在简化配置防火墙的过程。UFW默认安装在Ubuntu上。如果没有安装，你可以使用sudo apt-get install ufw 。</p>
<ul>
<li><p>ufw常见操作</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">sudo ufw status                 <span class="comment">#查看状态和规则</span></span><br><span class="line">sudo ufw <span class="built_in">disable</span>                <span class="comment">#禁用</span></span><br><span class="line">sudo ufw <span class="built_in">enable</span>                 <span class="comment">#启用</span></span><br><span class="line">sudo ufw reset                  <span class="comment">#重置</span></span><br><span class="line">sudo ufw status numbered        <span class="comment">#显示规则编号</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>设置默认策略</p>
<p>如果您刚刚开始使用防火墙，则首先要定义的规则是您的默认策略。这些规则控制如何处理未明确匹配任何其他规则的流量。</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo ufw<span class="built_in"> default </span>deny<span class="built_in"> incoming </span>  #拒绝所有传入连接</span><br><span class="line">sudo ufw<span class="built_in"> default </span>allow outgoing  #允许所有传出连接</span><br></pre></td></tr></table></figure>
</li>
<li><p>开启或禁用指定连接</p>
<figure class="highlight livecodeserver"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#允许连接</span></span><br><span class="line">sudo ufw allow 端口/服务</span><br><span class="line"></span><br><span class="line"><span class="comment">#允许ssh远程连接</span></span><br><span class="line">sudo ufw allow ssh  <span class="comment">#或者sudo ufw allow 22/tcp  </span></span><br><span class="line"></span><br><span class="line"><span class="comment">#允许未加密的web访问</span></span><br><span class="line">sudo ufw allow <span class="keyword">http</span>  <span class="comment">#或sudo ufw allow 80</span></span><br><span class="line"><span class="comment">#允许加密的web访问</span></span><br><span class="line">sudo ufw allow <span class="keyword">https</span>  <span class="comment">#或sudo ufw allow 443</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#允许ftp访问</span></span><br><span class="line">sudo ufw allow <span class="keyword">ftp</span>  <span class="comment">#或sudo ufw allow 21/tcp</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#允许远程mysql访问</span></span><br><span class="line">sudo ufw allow <span class="number">3306</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#允许特定范围的端口</span></span><br><span class="line">sudo ufw allow <span class="number">6000</span>:<span class="number">6007</span>/tcp <span class="comment">#允许使用端口6000 - 6007 X11连接</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#允许特定ip地址</span></span><br><span class="line">sudo ufw allow <span class="built_in">from</span> <span class="number">15.15</span><span class="number">.15</span><span class="number">.51</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#允许特定子网</span></span><br><span class="line">sudo ufw allow <span class="built_in">from</span> <span class="number">15.15</span><span class="number">.15</span><span class="number">.0</span>/<span class="number">24</span>  <span class="comment">#允许所有的IP地址范围从15.15.15.1到15.15.15.254</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#拒绝连接</span></span><br><span class="line">sudo ufw deny <span class="keyword">http</span></span><br><span class="line">sudo ufw deny <span class="built_in">from</span> <span class="number">15.15</span><span class="number">.15</span><span class="number">.51</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>删除规则</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sudo ufw status numbered <span class="comment">#先查看编号</span></span><br><span class="line">sudo ufw <span class="keyword">delete</span> <span class="number">2</span>  <span class="comment">#再按编号删除</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#按实际规则</span></span><br><span class="line">sudo ufw <span class="keyword">delete</span> <span class="keyword">allow</span> <span class="keyword">http</span></span><br><span class="line">sudo ufw <span class="keyword">delete</span> <span class="keyword">allow</span> <span class="number">80</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="三、nginx环境搭建"><a href="#三、nginx环境搭建" class="headerlink" title="三、nginx环境搭建"></a>三、nginx环境搭建</h2><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">安装nginx</span><br><span class="line"></span><br><span class="line"><span class="comment"># 1 更新软件列表</span></span><br><span class="line"></span><br><span class="line">sudo apt-<span class="builtin-name">get</span> update</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2 安装</span></span><br><span class="line"></span><br><span class="line">sudo apt-<span class="builtin-name">get</span> install nginx</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3 启动服务</span></span><br><span class="line"></span><br><span class="line">sudo  /etc/init.d/ngin start  # start | restart | stop</span><br><span class="line">或</span><br><span class="line">service nginx start | restart | stop</span><br><span class="line"></span><br><span class="line"><span class="comment"># 配置虚拟站点</span></span><br><span class="line"></span><br><span class="line">cd /etc/nginx/sites-available</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.复制虚拟站点配置模板，生成自己虚拟站点的配置文件</span></span><br><span class="line"></span><br><span class="line">sudo cp<span class="built_in"> default </span>www.blog.com.conf  </span><br><span class="line"></span><br><span class="line"><span class="comment"># 5 编辑模板</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ---------------------以下为配置内容-------------------</span></span><br><span class="line"></span><br><span class="line">server &#123;</span><br><span class="line">        listen 80; #监听端口</span><br></pre></td></tr></table></figure>
<p>   #站点的根目录<br>    root /var/www/html/<a href="http://www.blog.com" target="_blank" rel="noopener">www.blog.com</a>;</p>
<pre><code># Add index.php to the list if you are using PHP
#网站默认首页打开顺序
index index.html index.htm; 

#站点名称，可以有多个名称，中间用空格隔开
server_name www.blog.com blog.com; 
</code></pre><figure class="highlight dts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta"># ------------------到此结束------------------------------</span></span><br><span class="line"></span><br><span class="line"><span class="meta"># 这个模板比较简单，如果有复杂的要求，请以此为基础进行改进</span></span><br><span class="line"></span><br><span class="line"><span class="meta"># 6 保存退出</span></span><br><span class="line"></span><br><span class="line">:wq</span><br><span class="line"></span><br><span class="line"><span class="meta"># 7 切换到sites-enabled目录下，创建软连接</span></span><br><span class="line"></span><br><span class="line">cd ../sites-enabled</span><br><span class="line">sudo ln -s <span class="meta-keyword">/etc/</span>nginx<span class="meta-keyword">/sites-available/</span>www.blog.com.con   www.blog.com.conf</span><br><span class="line"></span><br><span class="line"><span class="meta"># 8 重启nginx服务</span></span><br><span class="line"></span><br><span class="line">sudo service nginx restart  (start/stop)</span><br><span class="line">或者</span><br><span class="line">sudo <span class="meta-keyword">/etc/</span>init.d/nginx restart</span><br><span class="line"></span><br><span class="line"><span class="meta"># 8 切换到站点根目录(根据你自己的设定进行)，我假定站点根目录是/var/www</span></span><br><span class="line"></span><br><span class="line">cd <span class="meta-keyword">/var/</span>www</span><br><span class="line">sudo chmod -R <span class="number">755</span> blog</span><br><span class="line"></span><br><span class="line"><span class="meta"># 编辑index.html</span></span><br><span class="line"></span><br><span class="line"><span class="params">&lt;html&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="params">&lt;head&gt;</span></span><br><span class="line"><span class="params">&lt;meta charset='utf<span class="number">-8</span>'&gt;</span></span><br><span class="line"><span class="params">&lt;title&gt;</span>疯狂程序员的博客<span class="params">&lt;/title&gt;</span></span><br><span class="line"><span class="params">&lt;/head&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="params">&lt;body&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="params">&lt;h1&gt;</span>疯狂的程序员<span class="params">&lt;/h1&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="params">&lt;/body&gt;</span></span><br><span class="line"><span class="params">&lt;/html&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="meta"># 保存退出</span></span><br><span class="line"></span><br><span class="line">:wq</span><br><span class="line"></span><br><span class="line"><span class="meta"># 9 切换到windows系统下，编辑C:\Windows\System32\drivers\etc\hosts文件，在末尾增加：</span></span><br><span class="line"></span><br><span class="line">ip为你虚拟机的ip地址</span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">192<span class="selector-class">.168</span><span class="selector-class">.48</span><span class="selector-class">.3</span>  <span class="selector-tag">www</span><span class="selector-class">.blog</span><span class="selector-class">.com</span>`   </span><br><span class="line"></span><br><span class="line">`10 在<span class="selector-tag">windows</span>系统下浏览器里输入 :  <span class="selector-tag">www</span><span class="selector-class">.blog</span><span class="selector-class">.com</span>`</span><br><span class="line"></span><br><span class="line">`看看是否是你的页面`</span><br></pre></td></tr></table></figure>
<h2 id="四、下载"><a href="#四、下载" class="headerlink" title="四、下载"></a>四、下载</h2><ul>
<li><p>wget  wget命令用来从指定的URL下载文件。wget非常稳定，它在带宽很窄的情况下和不稳定网络中有很强的适应性，如果是由于网络的原因下载失败，wget会不断的尝试，直到整个文件下载完毕。如果是服务器打断下载过程，它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。</p>
<figure class="highlight crystal"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#使用wget -c重新启动下载中断的文件，对于我们下载大文件时突然由于网络等原因中断非常有帮助，我们可以继续接着下载而不是重新下载一个文件。需要继续中断的下载时可以使用-c参数。</span></span><br><span class="line">sudo wget -c <span class="symbol">http:</span>/<span class="regexp">/mirrors.sohu.com/python</span><span class="regexp">/3.6.4/</span>Python-<span class="number">3.6</span>.<span class="number">4</span>.tar.xz</span><br><span class="line"></span><br><span class="line"><span class="comment">#-P 将下载文件存到指定目录</span></span><br><span class="line">sudo wget -c <span class="symbol">http:</span>/<span class="regexp">/mirrors.sohu.com/python</span><span class="regexp">/3.6.4/</span>Python-<span class="number">3.6</span>.<span class="number">4</span>.tar.xz -P ~<span class="regexp">/  #下载保存到家目录</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>curl</p>
<p>curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载，所以是综合传输工具，但按传统，习惯称curl为下载工具。</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -O http:<span class="regexp">//mi</span>rrors.sohu.com<span class="regexp">/python/</span><span class="number">3.6</span>.<span class="number">4</span><span class="regexp">/Python-3.6.4.tar.xz</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="五、python开发环境配置"><a href="#五、python开发环境配置" class="headerlink" title="五、python开发环境配置"></a>五、python开发环境配置</h2><p>Python 2和Python 3之间存在着较大的差异，并且，由于各种原因导致了Python 2和Python 3的长期共存。在实际工作过程中，我们可能会同时用到Python 2和Python 3，因此，也需要经常在Python 2和Python 3之间进行来回切换。这就需要对python的版本进行管理，除此之外还需要对不同的软件包进行管理。大部分情况下，对于开源的库我们使用最新版本即可。但是，有时候可能需要对相同的Python版本，在不同的项目中使用不同版本的软件包。</p>
<p>在这里，我们要使用两个工具：pyenv和virtualenv。前者用于管理不同的Python版本，后者用于管理不同的工作环境。有了这两个工具，Python相关的版本问题将不再是问题。</p>
<h3 id="5-1-pyenv"><a href="#5-1-pyenv" class="headerlink" title="5.1 pyenv"></a>5.1 pyenv</h3><p>pyenv是一个Python版本管理工具，它能够进行全局的Python版本切换，也可以为单个项目提供对应的Python版本。使用pyenv以后，可以在服务器上安装多个不同的Python版本，也可以安装不同的Python实现。不同Python版本之间的切换也非常简单。pyenv官方地址<a href="https://github.com/pyenv/pyenv-installer" target="_blank" rel="noopener">https://github.com/pyenv/pyenv-installer</a></p>
<ul>
<li>安装pyenv</li>
</ul>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1 安装pyenv，在命令行下键入：</span></span><br><span class="line">$ curl -L https:<span class="string">//github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer</span> | bash</span><br><span class="line"></span><br><span class="line"><span class="comment">#默认安装到当前用户的工作目录下的.pyenv，我们可以查看一下</span></span><br><span class="line">$ <span class="keyword">cd</span> ~</span><br><span class="line">$ <span class="keyword">ls</span> -la</span><br><span class="line"></span><br><span class="line"><span class="comment">#如果安装过git，也可以使用以下安装方式安装</span></span><br><span class="line"> $ git clone https:<span class="string">//github.com/pyenv/pyenv.git</span> ~<span class="string">/.pyenv</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2 将安装路径写入~/.bashrc</span></span><br><span class="line">将以下三条语句写入 ~<span class="string">/.bashrc</span>  </span><br><span class="line">export PATH=<span class="string">"/home/zhu/.pyenv/bin:$PATH"</span></span><br><span class="line">eval <span class="string">"$(pyenv init -)"</span></span><br><span class="line">eval <span class="string">"$(pyenv virtualenv-init -)"</span></span><br><span class="line"></span><br><span class="line">$ source  ~<span class="string">/.bashrc</span>  <span class="comment">#配置立刻生效</span></span><br><span class="line"></span><br><span class="line">$ <span class="keyword">echo</span> $PATH</span><br><span class="line"><span class="comment">#如果路径第一个结尾是shims则表示成功</span></span><br><span class="line"><span class="string">/home/python/.pyenv/plugins/pyenv-virtualenv/shims</span>:<span class="string">/home/python/.pyenv/shims</span>:<span class="string">/home/python/.pyenv/bin</span>:<span class="string">/home/python/bin</span>:<span class="string">/home/python/.local/bin</span>:<span class="string">/usr/local/sbin</span>:<span class="string">/usr/local/bin</span>:<span class="string">/usr/sbin</span>:<span class="string">/usr/bin</span>:<span class="string">/sbin</span>:<span class="string">/bin</span>:<span class="string">/usr/games</span>:<span class="string">/usr/local/games</span>:<span class="string">/snap/bin</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#也可以将上面三条命令写入到~/.barsh_profile，然后重启一下shell</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#3 更新一下</span></span><br><span class="line">$ pyenv update</span><br></pre></td></tr></table></figure>
<ul>
<li><p>使用pyenv</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1.查看pyenv当前支持哪些Python版本</span></span><br><span class="line">python@ubuntu:~$ pyenv install --list</span><br><span class="line">Available versions:</span><br><span class="line">  2.1.3</span><br><span class="line">  2.2.3</span><br><span class="line">  2.3.7</span><br><span class="line">  <span class="built_in">..</span>.</span><br><span class="line">  </span><br><span class="line"><span class="comment">#2.列出pyenv中所有可用的python版本</span></span><br><span class="line">python@ubuntu:~$ pyenv versions</span><br><span class="line">  system</span><br><span class="line">  3.5.4</span><br><span class="line">* 3.6.4 (<span class="builtin-name">set</span> by /home/python/.pyenv/version)  # *表示当前使用的3.6.4版本</span><br><span class="line"></span><br><span class="line"><span class="comment">#3.选择指定的python版本</span></span><br><span class="line">python@ubuntu:~$ pyenv global 3.5.4  #设置指定的版本</span><br><span class="line">python@ubuntu:~$ python  </span><br><span class="line">Python 3.5.4 (default, Mar 29 2018, 11:02:03)  #已经切换到了3.5.4</span><br><span class="line">[GCC 5.4.0 20160609] on linux</span><br><span class="line">Type <span class="string">"help"</span>, <span class="string">"copyright"</span>, <span class="string">"credits"</span> <span class="keyword">or</span> <span class="string">"license"</span> <span class="keyword">for</span> more information.</span><br><span class="line">&gt;&gt;&gt; </span><br><span class="line">切换Python版本以后，与版本相关的依赖也会一起切换。因此，我们不用担心不同的版本在系统中是否会相互干扰。</span><br><span class="line"></span><br><span class="line"><span class="comment">#4. 删除指定python版本</span></span><br><span class="line">python@ubuntu:~$ pyenv uninstall 3.5.4</span><br><span class="line">pyenv: <span class="builtin-name">remove</span> /home/python/.pyenv/versions/3.5.4? y</span><br><span class="line">python@ubuntu:~$ pyenv versions</span><br><span class="line">  system</span><br><span class="line">* 3.6.4 (<span class="builtin-name">set</span> by /home/python/.pyenv/version)</span><br></pre></td></tr></table></figure>
</li>
<li><p>安装python</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">1.在安装python之前，我们必须要安装python所需要的依赖包，这个必须要安装，安装会失败的：</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> sudo apt-get install libc6-dev gcc</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">2. 安装python</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> pyenv install 3.6.4 -v  <span class="comment">#-v 以日志模式显示安装过程</span></span></span><br><span class="line"><span class="meta">#</span><span class="bash">因为pyenv会自动到github上下载，速度超慢，所以一般会选择使用curl或者wget下载到~/.pyenv/cache下，然后再用pyenv安装，下面是可选的安装模式</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> <span class="built_in">cd</span> ~/.pyenv</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> sudo mkdir cache</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> wget -c http://mirrors.sohu.com/python/3.6.4/Python-3.6.4.tar.xz -P  ~/.pyenv/cache/</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> pyenv install 3.6.4 -v</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">3.更新pyenv数据库</span></span><br><span class="line"><span class="meta"> $</span><span class="bash"> pyenv <span class="built_in">rehash</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">4.列出所安装的python版本</span></span><br><span class="line"><span class="meta">  $</span><span class="bash"> pyenv versions</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">5.切换python版本</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> pyenv  global 3.6.4</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">6.验证版本</span></span><br><span class="line"><span class="meta"> $</span><span class="bash"> python</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>注意：</p>
<ul>
<li>使用pyenv管理python，必须是用pyenv安装的python才行，系统以前有的，需要重新用pyenv安装</li>
<li>使用pip安装第三方模块时会安装到~/.pyenv/versions/xxx下，不会和系统模块发生冲突；</li>
<li>使用pip安装模块后，可能需要执行pyenv rehash更新数据库。</li>
</ul>
</li>
</ul>
<h3 id="5-2-virtualenv"><a href="#5-2-virtualenv" class="headerlink" title="5.2 virtualenv"></a>5.2 virtualenv</h3><p>virtualenv本身是一个独立的项目，用以隔离不同项目的工作环境。例如，项目A和项目B都是使用Python 2.7.13，但是，项目A需要使用Flask 0.8版本，项目B需要使用Flask 0.9版本。我们只要组合pyenv和virtualenv这两个工具，就能够构造Python和第三方库的任意版本组合，拥有了很好的灵活性，也避免了项目之间的相互干扰。</p>
<p>virtualenv本身是一个独立的工具，用户可以不使用pyenv单独使用virtualenv。但是，如果你使用了pyenv，就需要安装pyenv-virtualenv插件而不是virtualenv软件来使用virtualenv的功能。</p>
<p>项目主页：<a href="https://github.com/yyuu/pyenv-virtualenv" target="_blank" rel="noopener">https://github.com/yyuu/pyenv-virtualenv</a></p>
<ul>
<li><p>安装virtualenv（可选）</p>
<p>如果是python3以上，安装完pyth就已经安装了virtualenv，就不用安装了</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#安装</span></span><br><span class="line">$ pip <span class="keyword">install</span> virtualenv</span><br><span class="line"></span><br><span class="line"><span class="comment">#或者，如果提示版本不匹配，可以使用--upgrade参数</span></span><br><span class="line">$ sudo pip <span class="keyword">install</span> <span class="comment">--upgrade virtualenv</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>使用virtualenv创建项目的虚拟环境</p>
</li>
</ul>
<p><strong>一个项目创建一个virtualenv的虚拟环境</strong>，在这个环境中，可以用pip安装项目所需的库，不会影响其他项目。切记一个项目一个虚拟环境，否则可能会发生莫名的错误。</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1.首先创建项目目录</span></span><br><span class="line">$ sudo mkdir -p myproject/blog</span><br><span class="line">cd myproject/blog</span><br><span class="line"></span><br><span class="line"><span class="comment">#2.创建项目的虚拟环境</span></span><br><span class="line"><span class="comment">#用法：pyenv virtualenv python版本号 虚拟环境名</span></span><br><span class="line">$ pyenv virtualenv 3.6.4 env36   #注意版本号必须是已经安装的，否则会报错</span><br><span class="line"></span><br><span class="line"><span class="comment">#3.切换到虚拟环境 </span></span><br><span class="line">python@ubuntu:/myproject/blog$ pyenv activate env36</span><br><span class="line"></span><br><span class="line">pyenv-virtualenv: prompt changing will be removed <span class="keyword">from</span> future release. configure `<span class="builtin-name">export</span> <span class="attribute">PYENV_VIRTUALENV_DISABLE_PROMPT</span>=1' <span class="keyword">to</span> simulate the behavior.</span><br><span class="line"></span><br><span class="line">(env36) python@ubuntu:/myproject/blog$  # (env36)表示该项目处于虚拟环境中</span><br><span class="line"></span><br><span class="line"><span class="comment">#验证</span></span><br><span class="line">(env36) python@ubuntu:/myproject/blog$ python</span><br><span class="line">Python 3.6.4 (default, Mar 29 2018, 10:33:37) </span><br><span class="line">[GCC 5.4.0 20160609] on linux</span><br><span class="line">Type <span class="string">"help"</span>, <span class="string">"copyright"</span>, <span class="string">"credits"</span> <span class="keyword">or</span> <span class="string">"license"</span> <span class="keyword">for</span> more information.</span><br><span class="line"></span><br><span class="line"><span class="comment">#4. 切出虚拟环境</span></span><br><span class="line">(env36) python@ubuntu:/myproject/blog$ pyenv deactivate env36</span><br></pre></td></tr></table></figure>
<p>1、安装  virtualenvwrapper</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">pip3 <span class="keyword">install</span> virtualenv</span><br><span class="line"></span><br><span class="line">pip3 <span class="keyword">install</span> virtualenvwrapper</span><br></pre></td></tr></table></figure>
<p> 2、新建虚拟环境文件夹</p>
<figure class="highlight plain"><figcaption><span>y</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir ~/PyEnv</span><br></pre></td></tr></table></figure>
<p>3、设置环境变量</p>
<pre><code>在使用virtualenvwrapper之前，要运行virtualenvwrapper.sh文件，需要设置环境变量， vim进入~/.bash_profile，插入
</code></pre><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">export</span> WORKON_HOME=~/PyEnv</span><br><span class="line"><span class="built_in">source</span> /usr/<span class="built_in">local</span>/bin/virtualenvwrapper.sh     //virtualenvwrapper.sh   所在目录</span><br></pre></td></tr></table></figure>
<p>4、执行3步骤，若提示</p>
<figure class="highlight smali"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">If Python could<span class="built_in"> not </span>import the module virtualenvwrapper.hook_loader,</span><br><span class="line">check that virtualenvwrapper has been installed for</span><br><span class="line">VIRTUALENVWRAPPER_PYTHON=/usr/bin/python<span class="built_in"> and </span>that PATH is</span><br><span class="line">set properly.</span><br></pre></td></tr></table></figure>
<p>在bash_profile中 加入</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">export VIRTUALENVWRAPPER_PYTHON=<span class="regexp">/usr/</span>local<span class="regexp">/bin/</span>python3   <span class="regexp">//</span>python3   所在目录</span><br></pre></td></tr></table></figure>
<p>5、至此mkvirtualenv、workon命令即可使用</p>
<figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">* </span>列出所有虚拟环境 workon</span><br><span class="line"><span class="bullet">* </span>创建基本环境 mkvirtualenv [环境名]</span><br><span class="line"><span class="bullet">* </span>激活环境 workon [环境名]</span><br><span class="line"><span class="bullet">* </span>退出环境 deactivate [环境名]</span><br><span class="line"><span class="bullet">* </span>删除环境 rmvirtualenv [环境名]</span><br></pre></td></tr></table></figure>
<ul>
<li>使用pip下载库</li>
</ul>
<p>使用pip下载，会从国外的网站下载，速度超慢，所以要切换pip到国内的镜像源，一般会用psm切换pip的源</p>
<ul>
<li><p>1.安装一个软件psm</p>
<figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">(bbs36)python<span class="variable">@ubuntu</span><span class="symbol">:/myproject/blog</span><span class="variable">$ </span>pip install psm</span><br><span class="line">[sudo] python 的密码： </span><br><span class="line">正在读取软件包列表... 完成</span><br><span class="line">正在分析软件包的依赖关系树       </span><br><span class="line">正在读取状态信息... 完成       </span><br><span class="line"><span class="symbol">E:</span> 无法定位软件包 psm</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li><p>2.psm的使用<br>以下操作需要在虚拟环境外进行，选择好镜像源后在进入虚拟环境</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1.查看列出pip的镜像源</span></span><br><span class="line">(bbs36)python@ubuntu:/myproject/blog$ psm ls</span><br><span class="line"></span><br><span class="line">pypi 	 https://pypi.python.org/simple/</span><br><span class="line">douban 	 http://pypi.douban.com/simple/</span><br><span class="line">aliyun 	 http://mirrors.aliyun.com/pypi/simple/</span><br><span class="line"></span><br><span class="line"><span class="comment">#查看当前的镜像源</span></span><br><span class="line">(bbs36)python@ubuntu:/myproject/blog$ psm <span class="keyword">show</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">Current</span> <span class="keyword">source</span> <span class="keyword">is</span> douban</span><br><span class="line"></span><br><span class="line"><span class="comment">#2.选择指定的镜像源</span></span><br><span class="line"></span><br><span class="line">(bbs36)python@ubuntu:/myproject/blog$ psm <span class="keyword">use</span> douban</span><br><span class="line"></span><br><span class="line"><span class="keyword">Source</span> <span class="keyword">is</span> <span class="keyword">changed</span> <span class="keyword">to</span> douban.</span><br><span class="line"></span><br><span class="line"><span class="comment">#3 使用pip下载库</span></span><br><span class="line">(bbs36) python@ubuntu:/myproject/blog$ pip <span class="keyword">install</span> pymysql</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="六、pycharm和虚拟开发环境结合"><a href="#六、pycharm和虚拟开发环境结合" class="headerlink" title="六、pycharm和虚拟开发环境结合"></a>六、pycharm和虚拟开发环境结合</h2><p>1.创建一个新的工程，file-setting-&gt;project  interpreter ，点击右边的…按钮–&gt;show all</p>
<p><img src="QQ截图20180913160545.png" alt="QQ截图20180913160545"></p>
<p><img src="env.png" alt="env"></p>
<p>点击“+”，然后，在下图中选择Existing interperter后面的….</p>
<p><img src="QQ截图20180913155916.png" alt="QQ截图20180913155916"></p>
<ol start="2">
<li><p>打开virtual enviroment   选择已经存在的虚拟开发环境. 在你的家目录下–&gt;.pyenv-&gt;versions –&gt; 你的虚拟开发环境名称–&gt;bin  选python</p>
<p><img src="QQ截图20180913160058.png" alt="QQ截图20180913160058"></p>
<p><img src="QQ截图20180913160400.png" alt="QQ截图20180913160400"></p>
<p><img src="QQ截图20180913160416.png" alt="QQ截图20180913160416"></p>
</li>
</ol>
<p>对已经存在的工程来说，file-&gt;settingd-&gt; project xxx –&gt;project interpreter  选择已经存在的虚拟开发环境i</p>
	
	</div>
	
	<div id="current-post-cover" data-scr="https://addyzk.github.io/Random-img/21.jpg"></div>

	<!-- relate post, comment...-->
	<div class="investment-container">
		<div class="investment-header">
			<div class="investment-title-1">
				<div class="on">相关文章</div>
				<div>评论</div>
				<div>分享</div>
			</div>
			<div class="investment-title-2">	            
				
	<span>
		<a href="javascript: window.scrollTo(0, 0);">返回顶部</a>
		
			<a href="../../../../2018/02/18/Django-rest-framework/" title="DRF" rel="prev">
				&laquo;上一篇
			</a>
		
		
			<a href="../../../../2016/05/17/my/" title="my" rel="next">
				下一篇&raquo;
			</a>
			
	</span>


      		
			</div>	
		</div>
		
		<div class="investment-content">
			<div class="investment-content-list">
				

<div class="relate-post">
	
		<ul>
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2019/05/28/linux/" title="linux">
								linux			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								五月 28日, 2019				
							</p>
							<p class="relate-post-content">
								一、课程简介
linux服务器配置及常用命令

开发软件配置及服务环境的搭建

软件的安装和配置

mysql数据库使用、monDB使用、redius的使用

git的使用

html/css


课程学习方式
表达训练     

...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2019/05/28/linux/" title="linux">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/88.jpg" alt="linux">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2019/05/16/hello-world/" title="Hello my friend!">
								Hello my friend!			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								五月 16日, 2019				
							</p>
							<p class="relate-post-content">
								Welcome to my blog ! This is your very first post. Check documentation for more info. If you get any problems when us...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2019/05/16/hello-world/" title="Hello my friend!">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/2.jpg" alt="Hello my friend!">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2019/04/18/Python进阶/" title="python进阶">
								python进阶			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								四月 18日, 2019				
							</p>
							<p class="relate-post-content">
								Python 进阶1. PEP8 编码规范, 及开发中的一些惯例和建议练习: 规范化这段代码
12345678910from django.conf import settingsfrom user.models import *im...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2019/04/18/Python进阶/" title="python进阶">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/28.jpg" alt="python进阶">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2018/10/12/mysql高级/" title="mysql高级">
								mysql高级			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								十月 12日, 2018				
							</p>
							<p class="relate-post-content">
								#mysql数据库
一、高级1.1 子查询
子查询嵌入到其他查询语句中查询语句，子查询只能出现在from，where中
子查询不要用select *,exists除外

12345678910select title from for...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2018/10/12/mysql高级/" title="mysql高级">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/15.jpg" alt="mysql高级">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2018/09/17/sql优化/" title="mysql优化">
								mysql优化			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								九月 17日, 2018				
							</p>
							<p class="relate-post-content">
								mysql优化一、数据库设计原则数据库设计的三范式学生表(学号，姓名，生日，课程名，课程成绩，等级，学院，院长)



学号
姓名
生日
课程号
课程名
成绩
等级
学院
院长




10001
张三
1998.1.1
tp3021...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2018/09/17/sql优化/" title="mysql优化">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/16.jpg" alt="mysql优化">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2018/08/29/网络编程/" title="网络编程">
								网络编程			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								八月 29日, 2018				
							</p>
							<p class="relate-post-content">
								计算机之间的通信，三次握手，四次挥手！TCP/UDP协议！
17 网络编程一、网络编程1.网络编程基础
计算机网络：把分布在不同区域的计算机通过专门的设备使用通信线路连接起来，从而会形成一个庞大的网络系统，不同的计算机之间就可以进行信...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2018/08/29/网络编程/" title="网络编程">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/1.jpg" alt="网络编程">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2018/05/12/redis/" title="redis">
								redis			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								五月 12日, 2018				
							</p>
							<p class="relate-post-content">
								redis教程：概述redis是一种支持分布式的nosql数据库,他的数据是保存在内存中，同时redis可以定时把内存数据同步到磁盘，即可以将数据持久化，并且他比memcached支持更多的数据结构(string,list列表[队列和...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2018/05/12/redis/" title="redis">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/10.jpg" alt="redis">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2018/04/27/项目部署/" title="项目部署">
								项目部署			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								四月 27日, 2018				
							</p>
							<p class="relate-post-content">
								一、项目部署基本流程1234567891011- 虚拟环境- 数据库- 项目上传- 项目依赖- 数据迁移- Nginx- uWSGI- Nginx和uWSGI对接
二、虚拟环境12345678910111213141516171819...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2018/04/27/项目部署/" title="项目部署">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/99.jpg" alt="项目部署">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2018/04/23/git/" title="Git!">
								Git!			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								四月 23日, 2018				
							</p>
							<p class="relate-post-content">
								Git 的基本认识，常用命令，以及使用流程，冲突管理分支管理等。
Git1.git简介1234- workspace 工作区- index 暂存区- repository 本地版本库- remote 远程仓库
2.常用git命令1所有...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2018/04/23/git/" title="Git!">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/47.jpg" alt="Git!">
							</a>
						</div>
					</li>											
			
			
					<li>
						<div class="relate-post-text">
							<a class="relate-post-title" href="../../../../2018/04/14/mysql/" title="mysql">
								mysql			
							</a>
							<p class="relate-post-date">
								<i class="fa fa-calendar"></i>
								四月 14日, 2018				
							</p>
							<p class="relate-post-content">
								数据库一、数据库基本概念数据的仓库:  
数据库服务器–&gt;数据库—&gt;表–&gt;记录-&gt;属性
1sudo apt-get install -y mysql-server mysql-client
二、SQL基本可分为...
							</p>
						</div>

						<div class="relate-post-cover">
							<a href="../../../../2018/04/14/mysql/" title="mysql">				
								
								<img class="lazy" src="/img/placeholder.jpg" data-src="https://addyzk.github.io/Random-img/13.jpg" alt="mysql">
							</a>
						</div>
					</li>											
			
			
		</ul>
	
</div>	
			</div>
			<div class="investment-content-list">
				<div class="layout-comment">

	

		

			<!-- gitalk comment -->
			<!-- show gitalk comment -->
<div id="gitalk-container"></div>

<!-- gitalk`s css & js -->
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<link rel="stylesheet" href="/SorrisiYi/css/comment.css">
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>

<script type="text/javascript">
	//Thanks O-R
	//https://github.com/gitalk/gitalk/issues/102#issuecomment-382970552
	//去除尾部匹配正则数组的字符串  
	//Remove redundant characters
	String.prototype.trimEnd = function(regStr) {
		var result = this;
		if(regStr == undefined || regStr == null || regStr == "") {
			return result;
		}
		var array = regStr.split(',');

		if(array.length > 0) {

			var c = array.shift();
			var str = this;
			var i = str.length;
			var rg = new RegExp(c);
			var matchArr = str.match(rg);

			if(matchArr != undefined && matchArr != null && matchArr.length > 0) {
				var matchStr = matchArr[0].replace(/\\/g, "\\\\").replace(/\*/g, "\\*")
					.replace(/\+/g, "\\+").replace(/\|/g, "\\|")
					.replace(/\{/g, "\\{").replace(/\}/g, "\\}")
					.replace(/\(/g, "\\(").replace(/\)/g, "\\)")
					.replace(/\^/g, "\\^").replace(/\$/g, "\\$")
					.replace(/\[/g, "\\[").replace(/\]/g, "\\]")
					.replace(/\?/g, "\\?").replace(/\,/g, "\\,")
					.replace(/\./g, "\\.").replace(/\&/g, "\\&");
				matchStr = matchStr + '$';
				result = str.replace(new RegExp(matchStr), "");
			}

			if(array.length > 0) {
				return result.trimEnd(array.join())
			} else {
				return result;
			}
		}
	};

	//Create gitalk
	var gitalk = new Gitalk({
		clientID: 'fa840d66074e8a6722c9',
		clientSecret: '039c6b559c7710f00e235c26795a2e2ecb613161',
		//id: window.location.pathname,
		//id: decodeURI(window.location.pathname),
		//id: (window.location.pathname).split("/").pop().substring(0, 49),
		id: decodeURI( md5( location.href.trimEnd('#.*$,\\?.*$,index.html$') ) ),
		repo: 'annie-gitalk',
		owner: 'SorrisoYi',
		admin: 'SorrisoYi',
		distractionFreeMode: 'true',
	})
	gitalk.render('gitalk-container');
</script>

		
		
	

</div>
			</div>
			<div class="investment-content-list">
				<div class="layout-share">
	
	

		

			<!-- addThis share -->
			<!-- www.addthis.com/dashboard -->

	<div class="addthis_inline_share_toolbox">
	</div>

	<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-xxx" async="async"></script>


		
		
	
</div>


			</div>
		</div>	
	</div>
	</div>
</div>



	<!-- leancloud -->
	<!--
	时间：2018-11-27
	描述：
		文章访问量：visitors
		文章喜欢量：likes	
		文章排行榜：topNPost
		其他得说明：
			01-Cookie相关的函数 
				https://blog.csdn.net/somehow1002/article/details/78511541（Author：somehow1002）
			02-visitors相关的函数 
				https://blog.csdn.net/u013553529/article/details/63357382（Author：爱博客大伯）
				https://notes.doublemine.me/2015-10-21-为NexT主题添加文章阅读量统计功能.html（Author：夏末）
			03-topNPost相关的函数
				https://hoxis.github.io/hexo-next-read-rank.html（Author：hoxis）
			04-likes相关的函数，
				参考了01 & 02进行简单的设计与实现
-->



	<script>
		var appid = 'bdanoXQN5zgeVyspG5e9RF7o-gzGzoHsz',
            appkey = 'RVVmwDan5FhjuwkKxenjOGSE';	  
        AnnieLeancloud(appid, appkey);         
	</script>
    

	


<!-- show math formula -->



	 
	<script src="../../../../plugin/clipboard/clipboard.js"></script>
	<script>
		// Copy code !
	    function codePreprocessing() {
	        $("#article-content .highlight").each(function() {

	            $(this).wrap('<div id="post-code"></div>');

	        })

	        $("#article-content #post-code").each(function() {

	            $(this).prepend('<nav class="copy-nav"><span><i class="code-language"></i></span></nav>');

	        })

	        $("#article-content .copy-nav").each(function() {
	            var temp = $(this).next().attr('class'),
	                language = ((temp.length > 9) && (temp != null)) ? temp.substr(10) : "none"; //why 9? Need to check language?

	            $(this).find('.code-language').text(language);

	            $(this).append('<span class="copy-btn"><i class="fa fa-copy" aria-hidden="true"></i></span>');

	        });
	    }

		function codeCopy() {
		    $('#article-content #post-code').each(function(i) {
		        var codeCopyId = 'codeCopy-' + i;

		        var codeNode = $(this).find('.code'),
		            copyButton = $(this).find('.copy-btn');

		        codeNode.attr('id', codeCopyId);
		        copyButton.attr('data-clipboard-target-id', codeCopyId);
		    })

		    
			var clipboard = new ClipboardJS('.copy-btn', {
					target: function(trigger) {
						return document.getElementById(trigger.getAttribute('data-clipboard-target-id'));
					}
		      	});

			//pure js
			function showTooltip(elem, msg) {		   
				elem.setAttribute('aria-label', msg);
				elem.setAttribute('class', 'copy-btn copy-status');
				setTimeout(function() {
					elem.setAttribute('class', 'copy-btn');
				}, 2000);
			}

			clipboard.on('success', function(e) {
			    e.clearSelection();
			    console.info('Action:', e.action);		   
			    console.info('Trigger:', e.trigger);
			    showTooltip(e.trigger, 'Copied!');
			    
			});
			clipboard.on('error', function(e) {
			    console.error('Action:', e.action);
			    console.error('Trigger:', e.trigger);
			});
		

		}

		if ($('.layout-post').length) {
		    codePreprocessing();
		    codeCopy();
		} 
	</script>





<link rel="stylesheet" href="../../../../plugin/fancybox/jquery.fancybox.css">
<script src="../../../../plugin/fancybox/jquery.fancybox.js"></script>

<script type="text/javascript">
	var titleID = $('.article-title a'),
		imageID = $('.article-content img'),
		videoID = $('.article-content video');

	var postTitle = titleID.text() ? titleID.text() : "No post title!";

	imageID.each(function() {
		var imgPath = $(this).attr('src'),
			imgTitle = $(this).attr('alt') ? $(this).attr('alt') : "No image description!";

		//给每个匹配的<img>元素打包, 即添加父元素<a>
		$(this).wrap('<a data-fancybox="gallery" data-caption=" 《 ' + postTitle + ' 》 ' + imgTitle + ' "  href=" ' + imgPath + ' "> </a>');
	});

	videoID.each(function() {
		var videoPath = $(this).attr('src');

		//给每个匹配的<img>元素打包, 即添加父元素<a>
		$(this).wrap('<a data-fancybox href=" ' + videoPath + ' "> </a>');
	});
	//TODO：支持html5 video

	if($('#layout-post').length) {
		$('[data-fancybox="gallery"]').fancybox({
			loop: true,
			buttons: [
				"zoom",
				"share",
				"slideShow",
				"fullScreen",
				//"download",
				"thumbs",
				"close"
			],
			protect: false
		});
	}
</script>
		</main>

		<!--footer-->
		<footer>
	<div class="social">
		<ul>
	
		<li>
			<a href="http://github.com/addyzk" target="_blank">
				<i class="fa fa-github"></i>
			</a>
		</li>
	
		<li>
			<a href="https://weibo.com/u/2943549915" target="_blank">
				<i class="fa fa-weibo"></i>
			</a>
		</li>
	
		<li>
			<a href="http://github.com/" target="_blank">
				<i class="fa fa-pinterest"></i>
			</a>
		</li>
	
		<li>
			<a href="http://github.com/" target="_blank">
				<i class="fa fa-instagram"></i>
			</a>
		</li>
	
		<li>
			<a href="http://github.com/" target="_blank">
				<i class="fa fa-twitter"></i>
			</a>
		</li>
	
		<li>
			<a href="../../../../atom.xml" target="_blank">
				<i class="fa fa-rss"></i>
			</a>
		</li>
			
</ul>

	</div>
		
	<div class="copyright">
		<p>
			 
				&copy;2016 - 2019, content by SorrisoYi. All Rights Reserved.
			
			
			

	<!-- busuanzi -->
	<!-- busuanzi -->

		
	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
	

		<span id="busuanzi_container_page_pv">
	  		本文总阅读量<span id="busuanzi_value_page_pv"></span>次
		</span>

	




		</p>
		<p>
			<a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a> Theme <a href="https://github.com/Sariay/hexo-theme-Annie" title="Annie" target="_blank" rel="noopener">Annie</a> by Sariay.
			<a href="javascript:zh_tran('s');" class="zh_click" id="zh_click_s">简体</a> 
			<a href="javascript:zh_tran('t');" class="zh_click" id="zh_click_t">繁體</a>				
		</p>
	</div>		
</footer>
		
	<!-- set '1' to show motto in all pages! -->

	<script src="../../../../plugin/motto/motto.js"></script>
	
	<script type="text/javascript">
		$(".motto").html( getMingYanContent() );
	</script>	




	<!--
	时间：2018-10-3
	描述：
		插件名称：hexo-generator-search-zip
		插件来源: https://github.com/SuperKieran/hexo-generator-search-zip
		代码参考：https://github.com/SuperKieran/TKL/blob/master/layout/_partial/search.ejs(Include: js & css)	
-->
<div class="popup search-popup local-search-popup">
	<div class="local-search-container">
		<span class="popup-btn-close">
      		ESC
   		</span>
		<div class="local-search-header">
			<div class="input-prompt">				
			</div>
			<input autocomplete="off" placeholder="Search..." type="text" id="local-search-input">
		</div>
		<div class="local-search-body">
			<div id="local-search-output"></div>
		</div>
		<div class="local-search-footer">
			<div class="topN-post">				
				

   
	<div id="topN">
		<div class="topN-title" data-title="热门文章"></div> 
	</div>
	
    <script>
        var appid = 'bdanoXQN5zgeVyspG5e9RF7o-gzGzoHsz',
            appkey = 'RVVmwDan5FhjuwkKxenjOGSE',
            limitCount = 10;
        if( $('#topN').length ){
            AV.initialize(appid, appkey);
            var Counter = AV.Object.extend("Counter");  
            topNPost(Counter, limitCount);
        }
    </script>
   
								
			</div>
		</div>
	</div>
</div>

<script src="../../../../plugin/search/ziploader.js"></script>
<script src="../../../../plugin/search/search.js"></script>

<script type="text/javascript">
	var search_path = 'search.json',
		zip_Path = '/SorrisiYi/search.zip',
		version_Path = '/SorrisiYi/searchVersion.txt',
		input_Trigger = 'auto',
		top_N = '2';

	themeLocalSearch({
		search_path, 
		zip_Path, 
		version_Path, 
		input_Trigger, 
		top_N
	});
</script>


<!-- love effect -->

	<script src="../../../../plugin/love/love.js"></script>


<!-- back to top -->

	
	<div id="totop">
  		<a href="javascript:;" name="TOTOP" class="fa fa-arrow-up"></a>
	</div>




<!-- site analysis -->


	<!-- site-analysis -->
	
	
	
	
	
 

<script src="../../../../plugin/vibrant/vibrant.js"></script>
<script src="../../../../plugin/chinese/chinese.js"></script>
<script src="../../../../plugin/imgLazyLoader/yall.min.js"></script>
<script src="../../../../plugin/imgResize/jquery.resizeimagetoparent.min.js"></script>
<script src="../../../../plugin/nicescroll/jquery.nicescroll.js"></script>
<script src="../../../../js/resizediv.js"></script>
<script src="../../../../js/main.js"></script>
	</body>	
</html>